/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package util.www.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import util.www.sql.SelectSql;

/**
 *
 * @author Rdelacruz 
 */
public class SelectJdbc
extends SelectSql
{    
            
    /*
    private final List<SeteadorJdbc> seteadores = new ArrayList<SeteadorJdbc>();
    
    public void agregarSeteador(SeteadorJdbc seteador) {
        seteadores.add(seteador);
    }
    
    public List getLista(Connection con, SeteadorJdbc seteador, Class claseParaInstanciar) throws SQLException {
        List lista = new ArrayList();
        Statement st = null;
        try {                        
            st = con.createStatement();                        
            String sql = this.getSql();
            ResultSet rs = st.executeQuery(sql);            
            while(rs.next()) {
                Object obj;
                try {
                    obj = claseParaInstanciar.newInstance();
                } catch (InstantiationException ex) {
                    throw new SQLException(ex);
                } catch (IllegalAccessException ex) {
                    throw new SQLException(ex);
                }
                
                for(SeteadorJdbc s: seteadores) {
                    s.setear(con, rs, obj);
                }
                
                lista.add(obj);
            }
        }
        finally {
            if(st!=null) st.close();
        }
        return lista;
    }
    */
    
    public final void ejecutarTodo(Connection con, OperadorResulSet operador) throws SQLException {
        Statement st = null;
        try {                        
            st = con.createStatement();                        
            String sql = this.getSql();
            ResultSet rs = st.executeQuery(sql);            
            while(rs.next()) {
                operador.operar(con,rs);
            }
        }
        finally {
            if(st!=null) st.close();
        }
    }   
    
    public final void ejecutarUnaVez(Connection con, OperadorResulSet operador) throws SQLException {
        Statement st = null;
        try {                        
            st = con.createStatement();                        
            String sql = this.getSql();
            ResultSet rs = st.executeQuery(sql);            
            if(rs.next()) {
                operador.operar(con,rs);
            }
        }
        finally {
            if(st!=null) st.close();
        }
    }  
    
}
